import React, { Component } from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'
import { adminRoutes } from './routes'
import FrameLayout from './layout'
import { connect } from 'react-redux'

const mapStateToProps = state => ({
  isLogin: state.users.isLogin
})

export default @connect(mapStateToProps) class App extends Component {
  render() {
    console.log(this.props.isLogin)
    return (
      <FrameLayout>
        {
          this.props.isLogin
          ?
          <Switch>
            {
              adminRoutes.map(route => (
                <Route key={route.path} path={ route.path } component={ route.component } />
              ))
            }
            <Redirect from="/admin" to="/admin/dashboard" />
            <Redirect to="/404" />
          </Switch>
          :
          <Redirect to="/login" />
        }
      </FrameLayout>
    )
  }
}
